import xadmin
from .models import CourseComments, UserAsk, UserCourse, UserFavourite, UserMessage


class CourseCommentsAdmin(object):
    list_display = ["name", "desc", "click_nums", "fav_nums", "image", "address", "city"]
    search_fields = ["name", "desc", "click_nums", "fav_nums", "image", "address", "city"]
    list_filter = ["name", "desc", "click_nums", "fav_nums", "image", "address", "city"]


class UserAskAdmin(object):
    """
        name = models.CharField(max_length=20, verbose_name="姓名")
        mobile = models.CharField(max_length=11, verbose_name="手机号")
        course_name = models.CharField(max_length=50, verbose_name="课程名")
        add_time = models.DateTimeField(default=datetime.now)
    """
    list_display = ["name", "mobile", "course_name", "add_time"]
    search_fields = ["name", "mobile", "course_name"]
    list_filter = ["name", "mobile", "course_name", "add_time"]


class UserCourseAdmin(object):
    """
        user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
        course = models.ForeignKey(Course, verbose_name="课程", on_delete=models.CASCADE)
        add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
    """
    list_display = ["user", "course", "add_time"]
    search_fields = ["user", "course"]
    list_filter = ["user", "course", "add_time"]


class UserFavouriteAdmin(object):
    """
        user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
        fav_id = models.IntegerField(default=0, verbose_name="数据ID")
        fav_type = models.IntegerField(choices=((1, "课程"), (2, "课程机构"), (3, "讲师")), verbose_name="收藏类型")
        add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")
    """
    list_display = ["user", "fav_id", "fav_type", "add_time"]
    search_fields = ["user", "fav_id", "fav_type"]
    list_filter = ["user", "fav_id", "fav_type", "add_time"]


class UserMessageAdmin(object):
    """
        user = models.IntegerField(default=0, verbose_name="接受用户ID")  # 0 代表发给所有人的消息
        message = models.CharField(max_length=500, verbose_name="消息内容")
        add_time = models.DateTimeField(default=datetime.now, verbose_name="发送时间")
        has_read = models.BooleanField(default=False, verbose_name="是否已读")
    """
    list_display = ["user", "message", "add_time", "has_read"]
    search_fields = ["user", "message", "has_read"]
    list_filter = ["user", "message", "add_time", "has_read"]


xadmin.site.register(CourseComments, CourseCommentsAdmin)
xadmin.site.register(UserAsk, UserAskAdmin)
xadmin.site.register(UserCourse, UserCourseAdmin)
xadmin.site.register(UserFavourite, UserFavouriteAdmin)
xadmin.site.register(UserMessage, UserMessageAdmin)